#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename	:  01-noAllowed-ordinary.sh
# Version	:  1.0
# Date		:  2020/05/31
# Author	:  Lz
# Email		:  lz843723683@gmail.com
# History	:     
#                  Version 1.0, 2020/05/31
# Function	: 测试三权分立 - 普通用户不被允许的操作
# Out		:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

# 测试主题
Title_Env_LTFLIB="三权分立(普通用户) - 普通用户不被允许的操作"

HeadFile_Source_LTFLIB="${LIB_SSHAUTO}"

testuser1_noAllowed="ltfnoAllowed"
passwd1_noAllowed="olleH717.12.#$"
userip_noAllowed="localhost"
AddUserNames_LTFLIB="${testuser1_noAllowed}"
AddUserPasswds_LTFLIB="${passwd1_noAllowed}"

## TODO : 个性化,初始化
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestInit_LTFLIB(){
        # 配置免密登录
        SshAuto_OneConfig_LTFLIB "${userip_noAllowed}" "${testuser1_noAllowed}" "${passwd1_noAllowed}"
        TestRetParse_LTFLIB "配置免密登录" "True" "no" "yes"

        SshAuto_SetIpUser_LTFLIB "${userip_noAllowed}" "${testuser1_noAllowed}"
        TestRetParse_LTFLIB "设置默认IP和用户名" "True" "no" "yes"

	return ${TPASS}
}


## TODO : 清理函数
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestClean_LTFLIB(){
	return ${TPASS}
}


## TODO ：查看审计日志
testcase_1(){
        local cmd="sudo ausearch --input-logs -i"

	SshAuto_CmdDef_LTFLIB "$cmd" "no" "yes"
        TestRetParse_LTFLIB "无法查看审计日志" "False"
}


## TODO ：关闭安全开关
testcase_2(){
	local cmd="sudo setenforce 0"

	SshAuto_CmdDef_LTFLIB "$cmd" "no" "yes"
	TestRetParse_LTFLIB "无法控制安全开关" "False"
}


## TODO ：关闭审计
testcase_3(){
        local cmd="sudo systemctl stop auditd"

        SshAuto_CmdDef_LTFLIB "$cmd" "no" "yes"
        TestRetParse_LTFLIB "无法关闭审计" "False"
}


## TODO ：修改安全开关
testcase_4(){
	local cmd="sudo echo test > /etc/sysconfig/selinux"

	SshAuto_CmdDef_LTFLIB "$cmd" "no" "yes"
	TestRetParse_LTFLIB "无法修改安全开关" "False"
}


## TODO ：查询布尔变量
testcase_5(){
	local cmd="sudo semanage boolean -l"

	SshAuto_CmdDef_LTFLIB "$cmd" "no" "yes"
	TestRetParse_LTFLIB "无法查询布尔变量" "False"
}


## TODO ：管理用户
testcase_6(){
	local cmd="sudo useradd ltftest1"

	SshAuto_CmdDef_LTFLIB "$cmd" "no" "yes"
	TestRetParse_LTFLIB "无法新增用户" "False"
}


## TODO ：用户切换
testcase_7(){
	local cmd="su"

	SshAuto_CmdDef_LTFLIB "$cmd" "no" "yes"
	TestRetParse_LTFLIB "无法用户切换" "False"
}


## TODO : 测试用例集
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
Testsuite_LTFLIB(){
	testcase_1
	testcase_2
	testcase_3
	testcase_4
	testcase_5
	testcase_6
	testcase_7

	return $TPASS
}


#----------------------------------------------#

source "${LIB_LTFLIB}"
Main_LTFLIB $@
